package com.service.impl;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.UserDao;
import com.entity.User;
import com.entity.page.Page;
import com.service.UserService;

@Transactional // 类所有方法都支持事物
@Service // 业务层
public class UserServiceImpl implements UserService {

	@Autowired
	UserDao userDao;

	// 该方法支持事物
	@Transactional(rollbackFor = Exception.class)
	@Override
	public boolean deleteUserById(Integer id) {
		return userDao.deleteUserById(id) > 0;
	}

	@Override
	public User login(String userCode, String userPassword) {
		return userDao.login(userCode, userPassword);
	}

	@Override
	public Page<User> selectByUserPage(int pageNo, String userName, Integer userRole) {
		Page<User> page = new Page<>(pageNo);
		page.setTotalCount(userDao.selectCount(userName, userRole));
		page.setDataList(userDao.selectUser(page.getStartRow(), page.getPageSize(), userName, userRole));
		return page;
	}

	@Override
	public boolean addUser(User user) {
		return userDao.addUser(user) > 0;
	}

	@Override
	public User selectUserById(Long id) {
		return userDao.selectUserById(id);
	}

	@Override
	public boolean ucexist(String userCode) {
		// TODO Auto-generated method stub
		return userDao.ucexist(userCode) > 0;
	}

}
